from itsdangerous import URLSafeTimedSerializer as Serializer
from meiduo_mall import settings
def generic_openid(openid):
    # 2.创建类的实例对象
    s = Serializer(settings.SECRET_KEY)
    # 3.加密数据
    token = s.dumps({'openid':openid})
    # 解密数据
    return token

def check_access_token(token):
    s = Serializer(settings.SECRET_KEY)
    try:
        result = s.loads(token,max_age=3600)
    except Exception:
        return None
    else:
        return result.get('openid')